from sanic import Sanic
from sanic.response import json,text
import asyncio

app = Sanic("__name__")

@app.route("/test" ,methods = ['GET','POST'])
async  def hello(request):

    questions = None
    q = request.args.get('q')
    print(q,type(q))
    if q:
        print(q)
        questions = q
    else:
        print(request.json)
        questions = request.json

    print(request.ip)
    print(request.method,request.port,request.headers)

    dict = {'answer':questions}
    print('请求地址：{},问题：{}'.format(request.ip, questions))
    return json(dict, content_type='application/json;charset=utf-8')


if __name__ == '__main__':
    app.run(host="192.168.1.193", debug=False, port=8600, access_log=False)